package io.bytestream;

import java.io.FileOutputStream;
import java.io.IOException;

public class Test4 {
    public static void main(String[] args) {
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("AdvancedCode/src/io/bytestream/info/info.txt",true);
            fos.write("\r\n".getBytes());
            fos.write("如果喜欢我的话，请多多为我投票wink~~".getBytes());
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            // 方式一：断言
            try {
                assert fos != null;
                fos.close();
            } catch (IOException | AssertionError e) {
                e.printStackTrace();
            }

            // 方式二：if
            /*try {
                if (fos != null) {
                    fos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }*/

            // 方式三：Objects.requireNonNull()
            /*try {
                Objects.requireNonNull(fos).close();
            } catch (IOException | NullPointerException e) {
                e.printStackTrace();
            }*/
        }

    }
}
